package com.xbao.core.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by qingshengzheng on 2019/1/3.
 */
@Configuration
public class SmSConfig {
    private static  final String product = "Dysmsapi";
    private static  final String domain = "dysmsapi.aliyuncs.com";
    @Value("${alisms.accessKeyId}")
    private  String accessKeyId = "LTAI6o7vhV2V4z5G";
    @Value("${alisms.accessKeySecret}")
    private  String accessKeySecret = "61TH4FZMsqD6fX2T0jo9lYexFjb4ys";


    @Bean
    public SmsSender buildSender(){
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId,
                accessKeySecret);
        try {
            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        IAcsClient acsClient = new DefaultAcsClient(profile);
        SmsSender sender=new SmsSender();
        sender.setAcsClient(acsClient);
        return sender;
    }
}
